package com.leven.easyerp.util;

import java.util.List;

/**
 * 字符串辅助工具类
 * 
 * @author Leven.Chen
 */
public class StringUtils extends org.apache.commons.lang3.StringUtils {
	/**
	 * 清空StringBuffer内容
	 */
	public static StringBuffer clear(StringBuffer buffer) {
		if (buffer == null || buffer.length() == 0) {
			return buffer;
		} else {
			return buffer.delete(0, buffer.length());
		}
	}

	/**
	 * 比较两字符串是否相等<br>
	 * null equals null = true<br>
	 * null equals "" = true<br>
	 * "" equals null = true<br>
	 * " " equals "" = true<br>
	 * "A" equals "a" = false
	 */
	public static boolean equals(String str1, String str2) {
		str1 = (str1 == null) ? "" : str1.trim();
		str2 = (str2 == null) ? "" : str2.trim();
		return str1.equals(str2);
	}

	/**
	 * 将一组字符串连接为一个字符串
	 * 
	 * @param items
	 * @param separator
	 *            分隔符
	 * @return
	 */
	public static String join(List<String> items, String separator) {
		if (items == null || items.isEmpty()) {
			return "";
		}
		int size = items.size();
		Object[] objs = new Object[size];
		for (int i = 0; i < size; i++) {
			objs[i] = items.get(i);
		}
		return join(objs, separator);
	}
}
